package org.openea.eap.module.obpm.model.custsql;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.openbpm.base.core.model.BaseModel;
import org.openea.eap.module.obpm.model.custsql.vo.SqlButtonVO;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 定制SQL列表
 */
@Accessors(chain = true)
@TableName(value = "form_cust_sql", autoResultMap = true)
@lombok.Data
public class FormCustSql
        extends BaseModel {
    private static final long serialVersionUID = -6953342097092685510L;

    private String name;
    private String code;
    private Integer type;
    private String content;

    private Integer status;

    private String dsKey;

    private String sqlContent;
    // string/json-array
    private String sqlTableList;  //解析SQL结果

    // subTable/json-array
    private List<FormCustSqlFields> fieldsList;

    // json-array
    //@TableField(value="buttons_json",typeHandler = CustJsonTypeHandler.class)
    private List<SqlButtonVO> buttonList;
    private String buttons;  //历史数据

    // json-array
    //@TableField(value="conditions_json",typeHandler = CustJsonTypeHandler.class)
    private List<SqlButtonVO> conditionList;
    private String conditions; //历史数据

    // json
    //@TableField(value="expand_json",typeHandler = ObjectJsonHandler.class)
    //private JSONObject expandJson;
    private String expand;  //历史数据

    private String groupId;  //定制SQL分组
    private String groupName;  //分组名
    private String tableName;  //关联数据表
    private String pkName;  //表主键
    private Integer initQuery;  //是否初始化查询
    private Integer canExport;  //是否允许导出
    private Integer pageSize;   //页面大小
    private Integer showRowsNum;  //是否显示行号
    private String crud;
    private Integer chart;

    private String creator;   //创建人
    private String updator;   //更新人

    // 是否冗余
    private String formKey;   //关联表单key

    // 临时变量
    private List<FieldGroup> groupsList;

    // 数据字典，需要从map改为list，增加可选的有效字段active/样式字段style
    // 排序字段sn(list排好序，可不需要sn字段）
    private Map<String, Object> dicMap;

    // 关联表单
    private FormCustSqlRelation custForm;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class FieldGroup {
        String groupName;
        Integer colspan;
    }


    class ButtonList extends ArrayList<SqlButtonVO> {

    }

    class ConditionList extends ArrayList<SqlButtonVO> {

    }

}
